package cn.topevery.garden.wapi.controller;

import cn.topevery.garden.dal.logic.ManholeReportLogic;
import cn.topevery.garden.entity.dto.ManholeReportDTO;
import cn.topevery.garden.entity.po.ManholeReport;
import cn.topevery.garden.entity.query.ManholeReportQuery;
import cn.topevery.garden.entity.vo.ManholeReportVO;
import com.github.dozermapper.core.Mapper;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.util.ExcelUtil;
import hw.topevery.framework.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 井盖信息上报表
 *
 * @author code-generate
 * @date 2021-08-17
 */
@Api(tags = "井盖信息上报表")
@RestController
@RequestMapping("/manhole")
public class ManholeReportController extends BaseController {


    @Autowired
    ManholeReportLogic manholeReportLogic;

    @Autowired
    private Mapper mapper;

    /**
     * 获取井盖信息上报表分页列表
     *
     * @param query
     * @return
     */
    @ApiOperation(value = "获取井盖信息上报表页列表")
    @PostMapping("/listPage")
    public JsonResult<DataPager<ManholeReportVO>> listPage(@RequestBody ManholeReportQuery query) {
        return JsonResult.ok(manholeReportLogic.listPage(query));
    }

    @ApiOperation(value = "保存")
    @PostMapping(value = "/saveOrUpdate")
    public JsonResult<?> saveOrUpdate(@RequestBody ManholeReportDTO dto) {
        manholeReportLogic.saveOrUpdate(getUser().id.toString(), mapper.map(dto, ManholeReport.class));
        return JsonResult.ok();
    }

    @ApiOperation("导出井盖信息上报表信息")
    @GetMapping("/export")
    public void export(ManholeReportQuery query, HttpServletResponse response) {
        List<ManholeReportVO> list = manholeReportLogic.listPage(query).records;
        ExcelUtil.exportExcel(list, "井盖信息上报表", "sheet1", ManholeReportVO.class, "井盖信息上报表", response);
    }

}
